package com.mason.forum.controller;

import com.mason.forum.common.ResultCode;
import com.mason.forum.exception.ApplicationException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.NonNull;
import org.springframework.web.bind.annotation.*;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 马拉圈
 * Date: 2023-10-01
 * Time: 20:29
 */

@Api(tags = "测试类的相关接口")
@RestController
@RequestMapping("/test")
public class TestController {

    @ApiOperation("测试接口1， 显示hi")
    @GetMapping("/hi")
    public String hi() {
        return "<h1>hi，Spring Boot project！</h1>";
    }


    @ApiOperation("测试接口2， 显示异常信息")
    @GetMapping("/ex1")
    public void ex1() throws Exception {
        throw new Exception("Exception！");
    }

    @ApiOperation("测试接口3， 显示自定义异常信息")
    @GetMapping("/ex2")
    public void ex2() {
        throw new ApplicationException(ResultCode.FAILED);
    }

    @ApiOperation("测试接口4， 给某人打招呼")
    @PostMapping("/hello")
    public String hello(@ApiParam("姓名") @RequestParam("name") @NonNull String name) {
        return "hello, " + name + " ! ";
    }

}
